
package com.hd.determine.modules.alarm.determine.judges;

import com.hd.common.constant.BizConstant;
import com.hd.determine.core.utils.StaticPropUtil;
import com.hd.determine.modules.alarm.Determiner;
import com.hd.determine.modules.alarm.model.AlarmRule;
import com.hd.determine.modules.alarm.util.AlarmUtils;
import com.hd.determine.modules.vehicle.model.VehicleEndPos;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author chentl
 * @version V1.0
 * @Project 交通运输第三方监测平台
 * @Title OffGpsDeterminer.java
 * @Description 夜间禁行研判者
 * @Package com.hd.sup.modules.alarm.determine.judges
 * @date 2021/1/29 11:26 上午
 * @Copyright: 深圳市宏电技术股份有限公司 All rights reserved.
 */
@Slf4j
public class NightNoEntryDeterminer extends Determiner<VehicleEndPos> {

    /**
     * @Description 速度溢出值
     * @Author chentl
     * @Create: 2021/1/20 6:02 下午
     */
    public static final int OVER_SPEED_INITAL = 15;

    public NightNoEntryDeterminer(VehicleEndPos data, AlarmRule alarmRule) {
        super(data, alarmRule);
    }

    @Override
    public void startDetermine() {

        boolean needMonitor = AlarmUtils.needMonitor(alarmRule.getStartTime(), alarmRule.getEndTime(), data.getGpsTime());
        boolean finishAuto = AlarmUtils.needMonitor(alarmRule.getStartTime(), alarmRule.getEndTime(), new Date());

        if (!finishAuto) {
            //当前时间超出夜间禁行时间后，强制结束当前车辆的夜间禁行报警
            needStop = true;
            return;
        }

        if (needMonitor) {
            boolean isAccOff = (data.getVehicleStatus() & 1) == 0;
            boolean speedOverflow = data.getSpeed() != null && data.getSpeed() > OVER_SPEED_INITAL;
            if (!isAccOff && speedOverflow) {
                //未熄火 直接判定为夜间行驶
                data.setBizAlarmType(BizConstant.AlarmType.NIGHT_NO_ENTRY.key());
                if (StaticPropUtil.SHOW_ALARM_LOG) {
                    log.info("[rabbitmq] 根据研判规则:{} 车辆：{} {}判定为 {} 报警", alarmRule.getRuleName(), data.getPlatNo(), data.getPlatNoColor(), alarmRule.getAlarmName());
                }
                needProduce = true;
                return;
            }
            if (isAccOff && !speedOverflow) {
                //停止报警
                needStop = true;
            }
        }

    }
}
